package org.jobtask.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;

import org.jobtask.config.ResourceMessages;
import org.jobtask.iface.ControlListener;

public class StatusBar extends JToolBar{

	private static final long serialVersionUID = 8979516925418397870L;
	
	private StartMenuButton startMenuButton=null;

	public StatusBar(CommonComponents components,ControlListener listener){
		this.setMargin(new Insets(0,0,0,0));
		this.setLayout(new BorderLayout());
		this.setFloatable(false);
		this.init(components,listener);
	}

	private void init(CommonComponents components,ControlListener listener){
		//状态栏的构建,这个是主面板
		JPanel stockPanel=new JPanel(new BorderLayout());
		//这个是左边的面板,主要显示当前任务的启动/停止数量和总数
		JPanel leftPanel=new JPanel();
		//这个是开始菜单和状态信息的面板
		this.startMenuButton=new StartMenuButton();
		JPanel centerPanel=new JPanel();
		
		JLabel startCountTitle=new JLabel(ResourceMessages.getString("CommonComp.17"),new ImageIcon(this.getClass().getResource("images/run.png")),JLabel.HORIZONTAL);
		JLabel stopCountTitle=new JLabel(ResourceMessages.getString("CommonComp.18"),new ImageIcon(this.getClass().getResource("images/stop.png")),JLabel.HORIZONTAL);
		JLabel totalCountTitle=new JLabel(ResourceMessages.getString("CommonComp.20"));
		//用于显示公司信息,或其他调试信息
		
		//存放当前已启动和已停止任务的状态数
		leftPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		leftPanel.add(totalCountTitle);
		leftPanel.add(components.getTotalCountLab());
		leftPanel.add(startCountTitle);
		leftPanel.add(components.getStartCountLab());
		leftPanel.add(stopCountTitle);
		leftPanel.add(components.getStopCountLab());
		
//		centerPanel.add(components.getMinInTrayCheckBut());
//		centerPanel.add(components.getWinTopCheckBut());
		
		
		stockPanel.add(leftPanel,BorderLayout.LINE_START);
		stockPanel.add(components.getInfoLab());
		
		this.add(stockPanel);
		
		//构建开始菜单
		components.getLogsMenu().setActionCommand("logsMenu");
		components.getLogsMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getLogsMenu());
		this.startMenuButton.addSeparator();
		
		components.getModifyTaskMenu().setActionCommand("modifyTaskMenu");
		components.getModifyTaskMenu().addActionListener(listener);		
		this.startMenuButton.addMenu(components.getModifyTaskMenu());
		
		components.getSaveMenu().setActionCommand("saveMenu");
		components.getSaveMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getSaveMenu());
		
		components.getReloadMenu().setActionCommand("reloadMenu");
		components.getReloadMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getReloadMenu());
		this.startMenuButton.addSeparator();
		
		components.getMinimiToTrayMenu().setActionCommand("minimiToTrayMenu");
		components.getMinimiToTrayMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getMinimiToTrayMenu());
		
		components.getWinTopMenu().setActionCommand("winTopMenu");
		components.getWinTopMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getWinTopMenu());
		
		components.getNurseMenu().setActionCommand("nurseMenu");
		components.getNurseMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getNurseMenu());
		this.startMenuButton.addSeparator();
		
		components.getHelpMenu().setActionCommand("helpMenu");
		components.getHelpMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getHelpMenu());
		
		components.getAboutMenu().setActionCommand("aboutMenu");
		components.getAboutMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getAboutMenu());
		
		components.getExitMenu().setActionCommand("exitMenu");
		components.getExitMenu().addActionListener(listener);
		this.startMenuButton.addMenu(components.getExitMenu());
		
		this.add(this.startMenuButton,BorderLayout.LINE_END);
	}
	
}
